package com.building.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.building.common.R;
import com.building.enums.REnum;
import com.building.service.impl.BaseServiceImpl.BaseServiceImpl;
import com.fasterxml.jackson.databind.ser.Serializers;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import java.util.List;
import com.building.entity.ShoppingOrderReceivingInformation;
import com.building.mapper.ShoppingOrderReceivingInformationMapper;
import com.building.service.ShoppingOrderReceivingInformationService;
/**
@author yinjiahui
@create 2021-04-11 17:11
*/
@Service
public class ShoppingOrderReceivingInformationServiceImpl extends BaseServiceImpl<ShoppingOrderReceivingInformationMapper, ShoppingOrderReceivingInformation> implements ShoppingOrderReceivingInformationService{

    @Override
    public int updateBatch(List<ShoppingOrderReceivingInformation> list) {
        return baseMapper.updateBatch(list);
    }
    @Override
    public int updateBatchSelective(List<ShoppingOrderReceivingInformation> list) {
        return baseMapper.updateBatchSelective(list);
    }
    @Override
    public int batchInsert(List<ShoppingOrderReceivingInformation> list) {
        return baseMapper.batchInsert(list);
    }
    @Override
    public int insertOrUpdate(ShoppingOrderReceivingInformation record) {
        return baseMapper.insertOrUpdate(record);
    }
    @Override
    public int insertOrUpdateSelective(ShoppingOrderReceivingInformation record) {
        return baseMapper.insertOrUpdateSelective(record);
    }

    /**
     * 根据用户id查询收货地址
     *
     * @param userId
     * @return
     */
    @Override
    public List<ShoppingOrderReceivingInformation> selectShoppingOrderReceivingInformationController(Integer userId) {
        QueryWrapper list = new QueryWrapper();
        list.eq("user_id",userId);
        return this.shoppingOrderReceivingInformationMapper.selectList(list);
    }

    /**
     * 新增或修改收货地址
     *
     * @param shoppingOrderReceivingInformation
     * @return
     */
    @Override
    public R insertOrUpdateShoppingOrderReceivingInformationController(ShoppingOrderReceivingInformation shoppingOrderReceivingInformation) {
        if (shoppingOrderReceivingInformation.getMaterialShoppingOrderReceivingInformationId() ==null){//新增

            this.shoppingOrderReceivingInformationMapper.insert(shoppingOrderReceivingInformation);
            return R.result(REnum.SUCCESS_INSERT);

        }else {//修改

            this.shoppingOrderReceivingInformationMapper.updateById(shoppingOrderReceivingInformation);
            return R.result(REnum.SUCCESS_UPDATE);

        }
    }

    /**
     * 根据收货地址id和用户id删除收货地址
     *
     * @param shoppingOrderReceivingInformationId
     * @param userId
     * @return
     */
    @Override
    public void deleteShoppingOrderReceivingInformationControllerByShoppingOrderReceivingInformationIdAndUserId(Integer shoppingOrderReceivingInformationId, Integer userId) {

        QueryWrapper del = new QueryWrapper();
        del.eq("user_id",userId);
        del.eq("material_shopping_order_receiving_information_id",shoppingOrderReceivingInformationId);

        this.shoppingOrderReceivingInformationMapper.delete(del);

    }
}
